package com.gwt.server.domain;

import javax.validation.constraints.DecimalMin;
import javax.validation.constraints.NotNull;

import com.gwt.server.BeerListService;

public class BeerStyle {
	/**
	 * The RequestFactory requires a static finder method for each proxied type.
	 * Soon it should allow you to customize how instances are found.
	 */
	public static BeerStyle findBeerStyle(String id) {
		return BeerListService.findBeer(id).getStyle();
	}

	// May be null if BeerStyle is newly-created
	private String id;

	@NotNull
	@DecimalMin("0")
	private Integer version = 0;

	@NotNull
	private String name;

	public BeerStyle() {
	}

	private BeerStyle(BeerStyle copyFrom) {
		copyFrom(copyFrom);
	}

	public void copyFrom(BeerStyle copyFrom) {
		id = copyFrom.id;
		version = copyFrom.version;
		name = copyFrom.name;
	}

	public String getId() {
		return id;
	}

	public Integer getVersion() {
		return version;
	}

	public String getName() {
		return name;
	}

	public BeerStyle makeCopy() {
		return new BeerStyle(this);
	}

	/**
	 * When this was written the RequestFactory required a persist method per
	 * type. That requirement should be relaxed very soon (and may well have
	 * been already if we forget to update this comment).
	 */
	public void persist() {
		BeerListService.persist(this);
	}

	public void setId(String id) {
		this.id = id;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}

	public void setName(String name) {
		this.name = name;
	}
}
